var Obj = {};
var browsingObj = {
  jump() {
    $(".back").click(function () {
     history.back();
    });
  },
  getData() {
    var url = `http://localhost:3000/browsing?userId=${localStorage.userId}`;
    axios.get(url).then(function (res) {
      browsingObj.render(res.data);
      browsingObj.deleteBrowsing(res.data);
    });
  },
  render(browsingList) {
    var str = "";
    browsingList.forEach(function (item) {
      str += `
             <div class="work bg-fff p-15 pb-5 bb3" >
            <p  class="flex aic jc-sb">${item.workTitle}<button data-id="${item.id}" class="btn"><span>x</span></button></p>
            <p class=" flex aic jc-sb mt-10"><span class="sc fw-600">${item.price}</span> <span class="f12 c888">${item.time}</span></p>
            <a href="./job-details.html?id=${item.positionId}" class="flex aic  mt-10">
                <span class="condition fcc f12 ">${item.conditionAddress}</span>
                <span class="condition fcc ml-10 f12 ">${item.conditionExperience}</span>
                <span class="condition fcc ml-10 f12 ">${item.conditionEdu}</span> 
              </a>
              <p class="logo f14 flex aic"><img src="${item.imgUrl}" alt=""> <span>${item.companyName}</span></p>
               </div>
            `;
      $("#browsing").html(str);
    });
  },
  deleteBrowsing(deleteData) {
    $(".btn").click(function () {
        var id = $(this).data("id");
        var url = "http://localhost:3000/browsing/" + id;
        axios.delete(url).then(function (res) {
            alert("删除成功");
        })
        $(this).parent().parent().remove();
    });
  },
};
browsingObj.jump();
browsingObj.getData();
